/* 
 * File:   WoodTexture.cpp
 * Author: brady
 * 
 * Created on May 10, 2011, 2:19 AM
 */

#include "WoodTexture.h"

WoodTexture::WoodTexture() {
    this->Color1 = Vector3D(0.2, 0.1, 0.0);
    this->Color2 = Vector3D(0.4, 0.3, 0.1);
    this->Alpha = 3;        //"persistence" means the inverse of alpha
    this->Beta = 2;
    this->Octaves = 4;
    this->bumpScale = 0.2;
    init();
}

WoodTexture::WoodTexture(const WoodTexture& orig) {
    this->Color1 = orig.Color1;
    this->Color2 = orig.Color2;
    this->Alpha = 3;        //"persistence" means the inverse of alpha
    this->Beta = 2;
    this->Octaves = 4;
    this->bumpScale = 0.2;
    init();
}

WoodTexture::~WoodTexture() {
}

Vector3D WoodTexture::GetColorAt(const Vector3D& point)
{
    //between -1 and 1
    double perlinValue = (PerlinNoise3D(point[0], point[1]/1.5, point[2], 3, 2, 4) + 2.0) * 25;

    
    double grainVal = perlinValue - (int)perlinValue;
    grainVal = fabs(grainVal)*.7;
    Vector3D final = (Color2*grainVal + Color2 * 0.3);
    return final;
}

Vector3D WoodTexture::GetNormalOffsetAt(const Vector3D& point) //make this somehow relative to normal direction
{
 //between -1 and 1
    Vector3D offset(1.0, 0.0, 0.0);
    Vector3D final;
    double perlinValue = PerlinNoise3D(point[0], point[1], point[2], 1.5, 2, 6);
    double gval = fabs(sin(point[0]*100)) -0.5 + perlinValue;
    final = offset*gval;
    final *= bumpScale;
    return final;
}